package com.loc;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.github.mikephil.charting.utils.Utils;
import com.sangfor.ssl.service.utils.IGeneral;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
import org.json.JSONObject;

/* compiled from: Cache.java */
/* loaded from: classes2.dex */
public final class fj {
    Hashtable<String, ArrayList<a>> a = new Hashtable<>();
    private long i = 0;
    private boolean j = false;
    private String k = "2.0.201501131131".replace(".", "");
    private String l = null;
    boolean b = true;
    long c = 0;
    String d = null;
    fa e = null;
    private String m = null;
    private long n = 0;
    boolean f = true;
    boolean g = true;
    String h = String.valueOf(AMapLocationClientOption.GeoLanguage.DEFAULT);

    /* JADX INFO: Access modifiers changed from: package-private */
    /* compiled from: Cache.java */
    /* loaded from: classes2.dex */
    public static class a {
        private ew a = null;
        private String b = null;

        protected a() {
        }

        public final ew a() {
            return this.a;
        }

        public final void a(ew ewVar) {
            this.a = ewVar;
        }

        public final void a(String str) {
            this.b = TextUtils.isEmpty(str) ? null : str.replace("##", "#");
        }

        public final String b() {
            return this.b;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x008b A[Catch: all -> 0x0094, TryCatch #0 {all -> 0x0094, blocks: (B:3:0x0001, B:5:0x0009, B:8:0x0012, B:10:0x001a, B:12:0x0022, B:14:0x0030, B:18:0x0048, B:20:0x0052, B:22:0x0064, B:25:0x006f, B:27:0x0073, B:29:0x0079, B:30:0x0085, B:32:0x008b, B:33:0x008f, B:16:0x0042), top: B:38:0x0001 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private com.loc.ew a(java.lang.String r5, java.lang.StringBuilder r6, boolean r7) {
        /*
            r4 = this;
            r0 = 0
            java.lang.String r1 = "cgiwifi"
            boolean r1 = r5.contains(r1)     // Catch: java.lang.Throwable -> L94
            if (r1 != 0) goto L42
            java.lang.String r1 = "wifi"
            boolean r1 = r5.contains(r1)     // Catch: java.lang.Throwable -> L94
            if (r1 == 0) goto L12
            goto L42
        L12:
            java.lang.String r6 = "cgi"
            boolean r6 = r5.contains(r6)     // Catch: java.lang.Throwable -> L94
            if (r6 == 0) goto L40
            java.util.Hashtable<java.lang.String, java.util.ArrayList<com.loc.fj$a>> r6 = r4.a     // Catch: java.lang.Throwable -> L94
            boolean r6 = r6.containsKey(r5)     // Catch: java.lang.Throwable -> L94
            if (r6 == 0) goto L40
            java.util.Hashtable<java.lang.String, java.util.ArrayList<com.loc.fj$a>> r6 = r4.a     // Catch: java.lang.Throwable -> L94
            java.lang.Object r6 = r6.get(r5)     // Catch: java.lang.Throwable -> L94
            java.util.ArrayList r6 = (java.util.ArrayList) r6     // Catch: java.lang.Throwable -> L94
            int r6 = r6.size()     // Catch: java.lang.Throwable -> L94
            if (r6 <= 0) goto L40
            java.util.Hashtable<java.lang.String, java.util.ArrayList<com.loc.fj$a>> r6 = r4.a     // Catch: java.lang.Throwable -> L94
            java.lang.Object r6 = r6.get(r5)     // Catch: java.lang.Throwable -> L94
            java.util.ArrayList r6 = (java.util.ArrayList) r6     // Catch: java.lang.Throwable -> L94
            r1 = 0
            java.lang.Object r6 = r6.get(r1)     // Catch: java.lang.Throwable -> L94
            com.loc.fj$a r6 = (com.loc.fj.a) r6     // Catch: java.lang.Throwable -> L94
            goto L46
        L40:
            r6 = r0
            goto L46
        L42:
            com.loc.fj$a r6 = r4.a(r6, r5)     // Catch: java.lang.Throwable -> L94
        L46:
            if (r6 == 0) goto L9c
            com.loc.ew r1 = r6.a()     // Catch: java.lang.Throwable -> L94
            boolean r1 = com.loc.gb.a(r1)     // Catch: java.lang.Throwable -> L94
            if (r1 == 0) goto L9c
            com.loc.ew r1 = r6.a()     // Catch: java.lang.Throwable -> L94
            java.lang.String r2 = "mem"
            r1.e(r2)     // Catch: java.lang.Throwable -> L94
            java.lang.String r2 = r6.b()     // Catch: java.lang.Throwable -> L94
            r1.h(r2)     // Catch: java.lang.Throwable -> L94
            if (r7 != 0) goto L85
            long r2 = r1.getTime()     // Catch: java.lang.Throwable -> L94
            boolean r7 = com.loc.fs.a(r2)     // Catch: java.lang.Throwable -> L94
            if (r7 == 0) goto L6f
            goto L85
        L6f:
            java.util.Hashtable<java.lang.String, java.util.ArrayList<com.loc.fj$a>> r7 = r4.a     // Catch: java.lang.Throwable -> L94
            if (r7 == 0) goto L9c
            boolean r7 = r7.containsKey(r5)     // Catch: java.lang.Throwable -> L94
            if (r7 == 0) goto L9c
            java.util.Hashtable<java.lang.String, java.util.ArrayList<com.loc.fj$a>> r7 = r4.a     // Catch: java.lang.Throwable -> L94
            java.lang.Object r5 = r7.get(r5)     // Catch: java.lang.Throwable -> L94
            java.util.ArrayList r5 = (java.util.ArrayList) r5     // Catch: java.lang.Throwable -> L94
            r5.remove(r6)     // Catch: java.lang.Throwable -> L94
            goto L9c
        L85:
            boolean r5 = com.loc.gb.a(r1)     // Catch: java.lang.Throwable -> L94
            if (r5 == 0) goto L8f
            r5 = 0
            r4.c = r5     // Catch: java.lang.Throwable -> L94
        L8f:
            r5 = 4
            r1.setLocationType(r5)     // Catch: java.lang.Throwable -> L94
            return r1
        L94:
            r5 = move-exception
            java.lang.String r6 = "Cache"
            java.lang.String r7 = "get1"
            com.loc.ft.a(r5, r6, r7)
        L9c:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.loc.fj.a(java.lang.String, java.lang.StringBuilder, boolean):com.loc.ew");
    }

    private a a(StringBuilder sb, String str) {
        a aVar;
        boolean z;
        a aVar2;
        if (this.a.isEmpty() || TextUtils.isEmpty(sb)) {
            return null;
        }
        if (this.a.containsKey(str)) {
            Hashtable hashtable = new Hashtable();
            Hashtable hashtable2 = new Hashtable();
            Hashtable hashtable3 = new Hashtable();
            ArrayList<a> arrayList = this.a.get(str);
            char c = 1;
            int size = arrayList.size() - 1;
            while (size >= 0) {
                a aVar3 = arrayList.get(size);
                if (!TextUtils.isEmpty(aVar3.b())) {
                    if (!a(aVar3.b(), sb)) {
                        z = false;
                    } else if (gb.a(aVar3.b(), sb.toString())) {
                        aVar2 = aVar3;
                        aVar = aVar2;
                        break;
                    } else {
                        z = true;
                    }
                    a(aVar3.b(), hashtable);
                    a(sb.toString(), hashtable2);
                    hashtable3.clear();
                    for (String str2 : hashtable.keySet()) {
                        hashtable3.put(str2, "");
                    }
                    for (String str3 : hashtable2.keySet()) {
                        hashtable3.put(str3, "");
                    }
                    Set keySet = hashtable3.keySet();
                    double[] dArr = new double[keySet.size()];
                    double[] dArr2 = new double[keySet.size()];
                    Iterator it = keySet.iterator();
                    int i = 0;
                    while (it != null && it.hasNext()) {
                        String str4 = (String) it.next();
                        double d = 1.0d;
                        dArr[i] = hashtable.containsKey(str4) ? 1.0d : 0.0d;
                        if (!hashtable2.containsKey(str4)) {
                            d = 0.0d;
                        }
                        dArr2[i] = d;
                        i++;
                    }
                    keySet.clear();
                    double[] a2 = a(dArr, dArr2);
                    if (a2[0] < 0.800000011920929d) {
                        aVar2 = aVar3;
                        if (a2[c] < Math.min(fs.g(), 0.618d)) {
                            if (z && a2[0] >= Math.min(fs.g(), 0.618d)) {
                            }
                        }
                        aVar = aVar2;
                        break;
                    }
                    aVar2 = aVar3;
                    aVar = aVar2;
                    break;
                }
                size--;
                c = 1;
            }
            aVar = null;
            hashtable.clear();
            hashtable2.clear();
            hashtable3.clear();
            return aVar;
        }
        return null;
    }

    private String a(String str, StringBuilder sb, Context context) {
        if (context == null) {
            return null;
        }
        JSONObject jSONObject = new JSONObject();
        try {
            this.l = gb.l(context);
            if (str.contains("&")) {
                str = str.substring(0, str.indexOf("&"));
            }
            String substring = str.substring(str.lastIndexOf("#") + 1);
            if (substring.equals("cgi")) {
                jSONObject.put("cgi", str.substring(0, str.length() - 12));
            } else if (!TextUtils.isEmpty(sb) && sb.indexOf(",access") != -1) {
                jSONObject.put("cgi", str.substring(0, str.length() - (substring.length() + 9)));
                String[] split = sb.toString().split(",access");
                jSONObject.put("mmac", split[0].contains("#") ? split[0].substring(split[0].lastIndexOf("#") + 1) : split[0]);
            }
            return p.b(fi.a(jSONObject.toString().getBytes("UTF-8"), this.l));
        } catch (Throwable unused) {
            return null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:110:0x02ae A[DONT_GENERATE] */
    /* JADX WARN: Removed duplicated region for block: B:112:0x02b3 A[DONT_GENERATE] */
    /* JADX WARN: Removed duplicated region for block: B:130:0x00c4 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:139:0x0270 A[EDGE_INSN: B:139:0x0270->B:88:0x0270 ?: BREAK  , SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:144:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:90:0x0280 A[LOOP:0: B:42:0x00d6->B:90:0x0280, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x028c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private void a(android.content.Context r20, java.lang.String r21, boolean r22) throws java.lang.Exception {
        /*
            Method dump skipped, instructions count: 721
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.loc.fj.a(android.content.Context, java.lang.String, boolean):void");
    }

    private void a(String str, AMapLocation aMapLocation, StringBuilder sb, Context context) throws Exception {
        if (context == null) {
            return;
        }
        if (this.l == null) {
            this.l = gb.l(context);
        }
        String a2 = a(str, sb, context);
        StringBuilder sb2 = new StringBuilder();
        SQLiteDatabase sQLiteDatabase = null;
        try {
            sQLiteDatabase = context.openOrCreateDatabase("hmdb", 0, null);
            sb2.append("CREATE TABLE IF NOT EXISTS hist");
            sb2.append(this.k);
            sb2.append(" (feature VARCHAR PRIMARY KEY, nb VARCHAR, loc VARCHAR, time VARCHAR);");
            sQLiteDatabase.execSQL(sb2.toString());
            sb2.delete(0, sb2.length());
            sb2.append("REPLACE INTO ");
            sb2.append("hist");
            sb2.append(this.k);
            sb2.append(" VALUES (?, ?, ?, ?)");
            Object[] objArr = new Object[4];
            objArr[0] = a2;
            byte[] a3 = fi.a(sb.toString().getBytes("UTF-8"), this.l);
            objArr[1] = a3;
            objArr[2] = fi.a(aMapLocation.toStr().getBytes("UTF-8"), this.l);
            objArr[3] = Long.valueOf(aMapLocation.getTime());
            for (int i = 1; i < 3; i++) {
                objArr[i] = p.b((byte[]) objArr[i]);
            }
            sQLiteDatabase.execSQL(sb2.toString(), objArr);
            sb2.delete(0, sb2.length());
        } catch (Throwable th) {
            try {
                ft.a(th, "DB", "updateHist");
                sb2.delete(0, sb2.length());
                if (sQLiteDatabase == null || !sQLiteDatabase.isOpen()) {
                    return;
                }
                sQLiteDatabase.close();
            } finally {
                sb2.delete(0, sb2.length());
                if (sQLiteDatabase != null && sQLiteDatabase.isOpen()) {
                    sQLiteDatabase.close();
                }
            }
        }
    }

    private static void a(String str, Hashtable<String, String> hashtable) {
        String[] split;
        if (TextUtils.isEmpty(str)) {
            return;
        }
        hashtable.clear();
        for (String str2 : str.split("#")) {
            if (!TextUtils.isEmpty(str2) && !str2.contains("|")) {
                hashtable.put(str2, "");
            }
        }
    }

    private boolean a(ew ewVar, boolean z) {
        if (a(z)) {
            return ewVar == null || fs.a(ewVar.getTime()) || z;
        }
        return false;
    }

    private static boolean a(String str, ew ewVar) {
        if (TextUtils.isEmpty(str) || !gb.a(ewVar) || str.startsWith("#")) {
            return false;
        }
        return str.contains(IGeneral.LOG_TAG_NETWORK);
    }

    private static boolean a(String str, StringBuilder sb) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(sb) || !str.contains(",access") || sb.indexOf(",access") == -1) {
            return false;
        }
        String[] split = str.split(",access");
        String substring = split[0].contains("#") ? split[0].substring(split[0].lastIndexOf("#") + 1) : split[0];
        if (TextUtils.isEmpty(substring)) {
            return false;
        }
        String sb2 = sb.toString();
        return sb2.contains(substring + ",access");
    }

    private boolean a(boolean z) {
        if (fs.e() || z) {
            return this.b || fs.f() || z;
        }
        return false;
    }

    private static double[] a(double[] dArr, double[] dArr2) {
        double[] dArr3 = new double[3];
        double d = Utils.DOUBLE_EPSILON;
        double d2 = 0.0d;
        double d3 = 0.0d;
        int i = 0;
        int i2 = 0;
        for (int i3 = 0; i3 < dArr.length; i3++) {
            d2 += dArr[i3] * dArr[i3];
            d3 += dArr2[i3] * dArr2[i3];
            d += dArr[i3] * dArr2[i3];
            if (dArr2[i3] == 1.0d) {
                i2++;
                if (dArr[i3] == 1.0d) {
                    i++;
                }
            }
        }
        dArr3[0] = d / (Math.sqrt(d2) * Math.sqrt(d3));
        double d4 = i;
        Double.isNaN(d4);
        double d5 = i2;
        Double.isNaN(d5);
        dArr3[1] = (d4 * 1.0d) / d5;
        dArr3[2] = d4;
        for (int i4 = 0; i4 < 2; i4++) {
            if (dArr3[i4] > 1.0d) {
                dArr3[i4] = 1.0d;
            }
        }
        return dArr3;
    }

    private boolean b() {
        long b = gb.b();
        long j = this.i;
        long j2 = b - j;
        if (j == 0) {
            return false;
        }
        return this.a.size() > 360 || j2 > 172800000;
    }

    private void c() {
        this.i = 0L;
        if (!this.a.isEmpty()) {
            this.a.clear();
        }
        this.j = false;
    }

    private void c(Context context) throws Exception {
        if (context == null) {
            return;
        }
        SQLiteDatabase sQLiteDatabase = null;
        try {
            SQLiteDatabase openOrCreateDatabase = context.openOrCreateDatabase("hmdb", 0, null);
            if (!gb.a(openOrCreateDatabase, "hist")) {
                if (openOrCreateDatabase == null || !openOrCreateDatabase.isOpen()) {
                    return;
                }
                openOrCreateDatabase.close();
                return;
            }
            String[] strArr = {String.valueOf(gb.a() - 172800000)};
            openOrCreateDatabase.delete("hist" + this.k, "time<?", strArr);
            if (openOrCreateDatabase == null || !openOrCreateDatabase.isOpen()) {
                return;
            }
            openOrCreateDatabase.close();
        } catch (Throwable th) {
            try {
                ft.a(th, "DB", "clearHist p2");
            } finally {
                if (0 != 0 && sQLiteDatabase.isOpen()) {
                    sQLiteDatabase.close();
                }
            }
        }
    }

    public final ew a(Context context, String str, StringBuilder sb, boolean z, boolean z2) {
        if (!TextUtils.isEmpty(str) && fs.e()) {
            String str2 = str + "&" + this.f + "&" + this.g + "&" + this.h;
            if (str2.contains(GeocodeSearch.GPS) || !fs.e() || sb == null) {
                return null;
            }
            if (b()) {
                c();
                return null;
            }
            if (z && !this.j) {
                try {
                    String a2 = a(str2, sb, context);
                    c();
                    a(context, a2, z2);
                } catch (Throwable unused) {
                }
            }
            if (this.a.isEmpty()) {
                return null;
            }
            return a(str2, sb, z2);
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0029 A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0044  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0086 A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x008d A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00b5 A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00ba A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00c3 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00d4 A[Catch: all -> 0x00ec, TryCatch #0 {all -> 0x00ec, blocks: (B:5:0x000f, B:7:0x0015, B:17:0x0029, B:27:0x004b, B:31:0x0053, B:33:0x0061, B:45:0x0086, B:47:0x008f, B:49:0x0093, B:51:0x0099, B:53:0x00a4, B:63:0x00c5, B:66:0x00d4, B:75:0x00e5, B:54:0x00a8, B:55:0x00ac, B:56:0x00b1, B:58:0x00b5, B:59:0x00ba, B:46:0x008d, B:39:0x0073, B:41:0x0079, B:9:0x0019, B:11:0x001d), top: B:79:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x00df A[ADDED_TO_REGION] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final com.loc.ew a(com.loc.fb r16, boolean r17, com.loc.ew r18, com.loc.fh r19, java.lang.StringBuilder r20, java.lang.String r21, android.content.Context r22, boolean r23) {
        /*
            Method dump skipped, instructions count: 237
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.loc.fj.a(com.loc.fb, boolean, com.loc.ew, com.loc.fh, java.lang.StringBuilder, java.lang.String, android.content.Context, boolean):com.loc.ew");
    }

    public final void a() {
        this.c = 0L;
        this.d = null;
    }

    public final void a(Context context) {
        if (this.j) {
            return;
        }
        try {
            c();
            a(context, (String) null, false);
        } catch (Throwable th) {
            ft.a(th, "Cache", "loadDB");
        }
        this.j = true;
    }

    public final void a(AMapLocationClientOption aMapLocationClientOption) {
        this.g = aMapLocationClientOption.isNeedAddress();
        this.f = aMapLocationClientOption.isOffset();
        this.b = aMapLocationClientOption.isLocationCacheEnable();
        this.h = String.valueOf(aMapLocationClientOption.getGeoLanguage());
    }

    public final void a(fa faVar) {
        this.e = faVar;
    }

    public final void a(String str) {
        this.d = str;
    }

    public final void a(String str, StringBuilder sb, ew ewVar, Context context, boolean z) {
        try {
            if (gb.a(ewVar)) {
                String str2 = str + "&" + ewVar.isOffset() + "&" + ewVar.i() + "&" + ewVar.j();
                if (!a(str2, ewVar) || ewVar.e().equals("mem") || ewVar.e().equals("file") || ewVar.e().equals("wifioff") || "-3".equals(ewVar.d())) {
                    return;
                }
                if (b()) {
                    c();
                }
                JSONObject f = ewVar.f();
                if (gb.a(f, "offpct")) {
                    f.remove("offpct");
                    ewVar.a(f);
                }
                if (str2.contains("wifi")) {
                    if (TextUtils.isEmpty(sb)) {
                        return;
                    }
                    if (ewVar.getAccuracy() >= 300.0f) {
                        int i = 0;
                        for (String str3 : sb.toString().split("#")) {
                            if (str3.contains(",")) {
                                i++;
                            }
                        }
                        if (i >= 8) {
                            return;
                        }
                    } else if (ewVar.getAccuracy() <= 3.0f) {
                        return;
                    }
                    if (str2.contains("cgiwifi") && !TextUtils.isEmpty(ewVar.g())) {
                        String replace = str2.replace("cgiwifi", "cgi");
                        ew h = ewVar.h();
                        if (gb.a(h)) {
                            a(replace, new StringBuilder(), h, context, true);
                        }
                    }
                } else if (str2.contains("cgi") && ((sb != null && sb.indexOf(",") != -1) || "4".equals(ewVar.d()))) {
                    return;
                }
                ew a2 = a(str2, sb, false);
                if (gb.a(a2) && a2.toStr().equals(ewVar.toStr(3))) {
                    return;
                }
                this.i = gb.b();
                a aVar = new a();
                aVar.a(ewVar);
                aVar.a(TextUtils.isEmpty(sb) ? null : sb.toString());
                if (this.a.containsKey(str2)) {
                    this.a.get(str2).add(aVar);
                } else {
                    ArrayList<a> arrayList = new ArrayList<>();
                    arrayList.add(aVar);
                    this.a.put(str2, arrayList);
                }
                if (z) {
                    a(str2, ewVar, sb, context);
                }
            }
        } catch (Throwable th) {
            ft.a(th, "Cache", "add");
        }
    }

    public final void b(Context context) {
        try {
            c();
            c(context);
            this.j = false;
            this.d = null;
            this.n = 0L;
        } catch (Throwable th) {
            ft.a(th, "Cache", "destroy part");
        }
    }
}
